﻿using System;
using System.Windows;
using System.Windows.Data;

namespace Dsl.Ped.Common.Converters
{
    /// <summary>
    /// Converts negated <see cref="Boolean"/> value to <see cref="Visibility"/> (true -> <see cref="Visibility.Collapsed"/> or <see cref="Visibility.Hidden"/>, false -> <see cref="Visibility.Visible"/>)
    /// If Conversion parameter is specified, the <see cref="Visibility.Collapsed"/> is prefered to the 
    /// <see cref="Visibility.Hidden"/>
    /// </summary>
    public class NegatedBoolToVisibilityValueConverter : IValueConverter
    {
        #region Implementation of IValueConverter

        /// <summary>
        /// Converts <see cref="Boolean"/> value to <see cref="Visibility"/>
        /// </summary>
        /// <param name="value"><see cref="Boolean"/> value to be converted</param>
        /// <param name="targetType">Target <see cref="Type"/> in the conversion</param>
        /// <param name="parameter">Conversion parameter</param>
        /// <param name="culture">Culture under the conversion is proceeded</param>
        /// <returns><see cref="Boolean"/> value converted into <see cref="Visibility"/></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool valueStrong = (bool)value;
            var negatedValueStrong = !valueStrong;

            var requestedTypeWhenParameter = Visibility.Hidden;
            if (parameter != null)
            {
                requestedTypeWhenParameter = Visibility.Collapsed;
            }

            return negatedValueStrong ? Visibility.Visible : requestedTypeWhenParameter;
        }

        /// <summary>
        /// Converts <see cref="Visibility"/> value back to <see cref="Boolean"/> value.
        /// </summary>
        /// <exception cref="NotImplementedException">Method is not implemented</exception>
        /// <returns>Nothing, throws a <see cref="NotImplementedException"/></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
